package com.iterator.iface.impl;

import com.iterator.iface.Aggregate;
import com.iterator.iface.Iterator;

import java.util.ArrayList;
import java.util.List;

/*
    具体的聚合类，可以使用任意集合结构，以下使用List
 */
public class AggregateImpl implements Aggregate {

    private List<Object> list = new ArrayList<>();

    @Override
    public void add(Object element) {
        list.add(element);
    }

    @Override
    public void remove(Object element) {
        list.remove(element);
    }

    @Override
    public Iterator getIterator() {
        return new IteratorImpl(list);
    }
}
